import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import { AppRouteModule } from "./type";
import store from '../store';

let routes: Array<AppRouteModule> = [
    {
        path: '/',
        redirect: '/brand'
    }
]

const routesmModules = import.meta.globEager('./modules/*.ts');
const modules: AppRouteModule[] = [];
Object.keys(routesmModules).forEach(key => {
    modules.push(...routesmModules[key].default);
});
routes = routes.concat(...modules);

const router = createRouter({
    history: createWebHashHistory(),
    routes: (routes as unknown) as RouteRecordRaw[]
});

router.beforeEach(async (to, from, next) => {
    const { keepAlive= false, is_show_header= false, is_show_footer= false, title='' } = to.meta;

    // store.commit('setting/set_router_meta',
    // {
    //     keepAlive,
    //     is_show_header,
    //     is_show_footer,
    //     title,
    // });
    to.meta.title?(document.title = to.meta.title as string):( document.title = 'home' );
    next();
});

export default router;



